package cn.lbd.city.controller;


import cn.lbd.city.entity.CityInfo;
import cn.lbd.city.feignService.ReportMicService;
import cn.lbd.city.service.ChartService;
import cn.lbd.city.utils.HttpResult;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/echarts")
//@PreAuthorize("hasAuthority('13100900')")  //10000025无此权限
public class ChartController {
    @Autowired
    private ChartService service;
    @Autowired
    private ReportMicService reportService;

    //城市地图
    @PostMapping(value = "/findCityInfo",produces = "text/json;charset=UTF-8" )
    public String findCityInfo(@RequestBody String cityCode){
        log.info("城市微服务调用....");
        String s = cityCode.split("=")[0];
        int code = Integer.parseInt(s);
        List<CityInfo> cityInfoList = service.findCityInfoByCityCode(code);

        List<CityInfo> list = new ArrayList<>();

        for (CityInfo cityInfo : cityInfoList){
            if (cityInfo.getParentId()==code){
                list.add(cityInfo);
            }
        }
        return JSON.toJSONString(list) + "/" +JSON.toJSONString(reportService.test());
    }

    @PostMapping("/test")
    public HttpResult test() {
        System.out.println("城市微服务被调用");
        return HttpResult.ok("City Mic Service >...................");
    }

}
